﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace Ring2Park.Models
{
    public class SampleData : DropCreateDatabaseIfModelChanges<Ring2ParkEntities>
    {
        protected override void Seed(Ring2ParkEntities context)
        {

            var vehicles = new List<Vehicle>
            {
                new Vehicle { UserName = "test1", Color = "Black", License = "ABC 123" },
                new Vehicle { UserName = "test2", Color = "White", License = "DEF 456" },
                new Vehicle { UserName = "test3", Color = "Silver", License = "XYZ 789" },
                new Vehicle { UserName = "test3", Color = "Red", License = "UUU 111" }
            };

            vehicles.ForEach(d => context.Vehicles.Add(d));

            var parkingLocations = new List<ParkingLocation>
            {
                new ParkingLocation { Name = "Wembley Stadium", Location = "Wembley, London" },
                new ParkingLocation { Name = "Liverpool St. Station", Location = "Liverpool St., London" }
            };

            parkingLocations.ForEach(d => context.ParkingLocations.Add(d));

            var parkingSessions = new List<ParkingSession>
            {
                new ParkingSession { UserName = "test1", 
                    ParkingLocationId = parkingLocations.Single(p => p.Name == "Wembley Stadium").ParkingLocationId,
                    VehicleId = vehicles.Single(v => v.License == "ABC 123").VehicleId, 
                    StartDate = DateTime.Now, Duration = 1 },
                new ParkingSession { UserName = "test2", 
                    ParkingLocationId = parkingLocations.Single(p => p.Name == "Liverpool St. Station").ParkingLocationId,
                    VehicleId = vehicles.Single(v => v.License == "DEF 456").VehicleId, 
                    StartDate = DateTime.Now, Duration = 2 },
                new ParkingSession { UserName = "test3", 
                    ParkingLocationId = parkingLocations.Single(p => p.Name == "Wembley Stadium").ParkingLocationId,
                    VehicleId = vehicles.Single(v => v.License == "XYZ 789").VehicleId, 
                    StartDate = DateTime.Now, Duration = 1 }
            };

            vehicles.ForEach(d => context.Vehicles.Add(d));

        }
    }
}